<?

  $currentWealth = $this->character->getMoney();
  
  include('custom/shoptabs.php');

?>
<h3>Buy Stuff</h3>
<table width="650"><?
foreach(DB_GetList('SELECT * FROM '.getTableName('shopitems').
  ' LEFT JOIN '.getTableName('items').' ON (s_item=i_key)
    LEFT JOIN '.getTableName('inventory').' ON (s_item=iv_item AND iv_character='.$this->character->charDS['c_key'].')
  WHERE s_zone="'.$this->character->charDS['c_location'].'"
    OR (s_fromlevel <= '.$this->character->level.' AND s_tolevel >= '.$this->character->level.')
  ORDER BY i_value') as $itemDS) if ($itemDS['i_value'] > 0) if ($itemDS['i_description']!='')
{
  $rowCtr++;
  ?><tr>
    <td valign="top" width="40"><img width="32" src="img/<?= $itemDS['i_icon'] ?>.png"/></td>
    <td valign="top" width="*">
      <b><?= $itemDS['i_name'] ?></b><br/>
      <?= $itemDS['i_description'] ?>
      <?
      if ($itemDS['iv_key'] > 0)
        print('<br/><span style="color: gray">You already have '.$itemDS['iv_quantity'].' of these.</span>');
      ?>
    </td>
    <td valign="top" width="32">
    <? 
      $itxt = $this->character->explainItem($itemDS);
      if ($itxt != '') {
        ?><img src="img/icons/restart.png" <?= ToolTip(':'.$itxt) ?>/><?
    } ?>    
    </td>
    <td id="slr_<?= $rowCtr ?>" valign="top" nowrap width="130">
    <?
    if ($currentWealth < $itemDS['i_value'])
    {
      ?><b style="color: gray"><?= $itemDS['i_value']?> gold</b><?
    }
    else
    {
      ?><input type="button" name="buy" style="width: 120px" 
        onclick="$('#slr_<?= $rowCtr ?>').fadeTo('slow', 0.2); document.location='<?= actionUrl('index', 'shop', 'buy='.$itemDS['i_key']) ?>';"
        value="buy for <?= $itemDS['i_value'] ?> gold"/><?
    }
    ?></td>
    <td valign="top" width="150">
      
    </td>
  </tr><?
}

?></table>
